package com.managementControllers
import com.*;
import com.authen.*;
import com.webboard.*;
import com.diseaseInformation.*;


class SearhLayoutController {
    static String WILDCARD = "*"
    def searchableService
    def index = {    
        def searchResult = [:]
        if (!params.q?.trim()) {
            return [:]
        }else{
            def searchInput = WILDCARD+params.q+WILDCARD
            if(params.sb == 'all'){
                searchResult = searchableService.search(searchInput,params)
            }
            else if(params.sb == 'user'){  //Search User
                searchResult = User.search(searchInput,params)
            }
            else if(params.sb == 'webboard'){ //Search Webboard [post And reply]
                //searchResult = Post.search(searchInput,params)
                searchResult = post.search(searchInput,params)
                //searchResult.putAll(Reply.search(searchInput,params))
            }
            else if(params.sb == 'problem'){
                searchResult = Problem.search(searchInput,params)
            }
        }
        assert searchResult instanceof Map
        [searchResult : searchResult]
    }
    
    
    def diseaseSearch = {
        def searchInput = WILDCARD+params.qDisease+WILDCARD
        if (!params.qDisease?.trim()) {
            return [:]
        }
        else{
            [searchResult : Disease.search(searchInput,params)]
        }
    }
}
